package com.yf.system.modules.points.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.system.modules.points.dto.UserPointsDTO;
import com.yf.system.modules.points.service.UserPointsService;
import com.yf.system.modules.user.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* 积分日志控制器
* </p>
*
* @author 聪明笨狗
* @since 2021-02-20 09:09
*/
@Api(tags={"积分日志"})
@RestController
@RequestMapping("/api/user/points")
public class UserPointsController extends BaseController {

    @Autowired
    private UserPointsService baseService;


    /**
    * 分页查找
    * @param reqDTO
    * @return
    */
    @RequiresPermissions(value = {"sys:user:points"})
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<UserPointsDTO>> paging(@RequestBody PagingReqDTO<UserPointsDTO> reqDTO) {

        //分页查询并转换
        IPage<UserPointsDTO> page = baseService.paging(reqDTO);

        return super.success(page);
    }

    /**
     * 我的积分明细
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "我的积分明细")
    @PostMapping("/my-paging")
    public ApiRest<IPage<UserPointsDTO>> myPaging(@RequestBody PagingReqDTO<UserPointsDTO> reqDTO) {

        UserPointsDTO params = reqDTO.getParams();
        if(params == null){
            params = new UserPointsDTO();
        }

        // 置入用户ID
        params.setUserId(UserUtils.getUserId());
        reqDTO.setParams(params);

        //分页查询并转换
        IPage<UserPointsDTO> page = baseService.paging(reqDTO);

        return super.success(page);
    }

}
